
import GameDataUtilTs from "../Utils/GameDataUtilTs";
import GameLogicUtilTs from "../Utils/GameLogicUtilTs";

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.node.on("msgwatcher_add",this._onMsgWatcherAdd.bind(this),this)
    },

    _onMsgWatcherAdd:function (callback) {
        GameLogicUtilTs.msgWathcerCallbacks.push(callback)
    },

    start () {

    },

    update (dt) {
        if(!this.node){
            cc.error("MessageWatcher must be component of a Node!")
            return
        }

        for(let i=0;i<GameLogicUtilTs.msgWathcerCallbacks.length;i++){
            if(GameLogicUtilTs.msgWathcerCallbacks[i]()){
                GameLogicUtilTs.msgWathcerCallbacks.splice(i--,1)
            }
        }
    },
});
